package writer;

import java.io.FileWriter;
import java.io.IOException;

/**
 * @author 培培
 * @condition 努力学习中
 */
public class FileWriter_ {
    public static void main(String[] args) {

        String filePath = "d:\\note.txt";
        //创建FileWriter 对象
        FileWriter fileWriter = null;
        char[] chars = {'a','b','c'};

        try {
            fileWriter = new FileWriter(filePath);//默认是覆盖写入

            //write(int):写入单个字符
            fileWriter.write('H');

            //write(char[]): 写入指定数组
            fileWriter.write(chars);

            //write(char[] ,off,len) : 写入指定数组的指定部分
            fileWriter.write("努力学习".toCharArray(),0,2);

            //write(String) : 写入整个字符串
            fileWriter.write("你好北京");

            //write(String,off,len) : 写入字符串的指定部分
            fileWriter.write("继续加油", 0,2);


        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                //fileWriter.flush();
                fileWriter.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
